package com.haixiaoke.saas.enterprise.bill.controller;

import com.haixiaoke.saas.bill.domain.ProprietorBill;
import com.haixiaoke.saas.bill.service.IProprietorBillService;
import com.haixiaoke.saas.common.annotation.Log;
import com.haixiaoke.saas.common.annotation.TenantScope;
import com.haixiaoke.saas.common.core.domain.AjaxResult;
import com.haixiaoke.saas.common.core.page.TableDataInfo;
import com.haixiaoke.saas.common.enums.BusinessType;
import com.haixiaoke.saas.common.utils.poi.ExcelUtil;
import com.haixiaoke.saas.system.BaseController;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

import static com.haixiaoke.saas.common.tenant.TenantContext.getTenantId;

/**
 * 业主账单Controller
 *
 * @author qixi
 * @date 2024-05-28
 */
@RestController
@RequestMapping("/enterprise/bill/proprietor")
public class EnterpriseProprietorBillController extends BaseController {
    @Autowired
    private IProprietorBillService proprietorBillService;

    /**
     * 查询业主账单列表
     */
    @PreAuthorize("@ss.hasPermi('bill:proprietor:list')")
    @GetMapping("/list")
    @TenantScope
    public TableDataInfo list(ProprietorBill proprietorBill) {
        startPage();
        proprietorBill.setTenantId(getTenantId());
        List<ProprietorBill> list = proprietorBillService.selectProprietorBillList(proprietorBill);
        return getDataTable(list);
    }

    /**
     * 导出业主账单列表
     */
    // @PreAuthorize("@ss.hasPermi('bill:proprietor:export')")
    @Log(title = "业主账单", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ProprietorBill proprietorBill) {
        List<ProprietorBill> list = proprietorBillService.selectProprietorBillList(proprietorBill);
        ExcelUtil<ProprietorBill> util = new ExcelUtil<ProprietorBill>(ProprietorBill.class);
        util.exportExcel(response, list, "业主账单数据");
    }

    /**
     * 获取业主账单详细信息
     */
    @PreAuthorize("@ss.hasPermi('bill:proprietor:query')")
    @GetMapping(value = "/{proprietorBillId}")
    public AjaxResult getInfo(@PathVariable("proprietorBillId") String proprietorBillId) {
        return success(proprietorBillService.selectProprietorBillByProprietorBillId(proprietorBillId));
    }

    /**
     * 新增业主账单
     */
    // @PreAuthorize("@ss.hasPermi('bill:proprietor:add')")
    @Log(title = "业主账单", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ProprietorBill proprietorBill) {
        return toAjax(proprietorBillService.insertProprietorBill(proprietorBill));
    }

    /**
     * 修改业主账单
     */
    // @PreAuthorize("@ss.hasPermi('bill:proprietor:edit')")
    @Log(title = "业主账单", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ProprietorBill proprietorBill) {
        return toAjax(proprietorBillService.updateProprietorBill(proprietorBill));
    }

    /**
     * 删除业主账单
     */
    // @PreAuthorize("@ss.hasPermi('bill:proprietor:remove')")
    @Log(title = "业主账单", businessType = BusinessType.DELETE)
    @DeleteMapping("/{proprietorBillIds}")
    public AjaxResult remove(@PathVariable String[] proprietorBillIds) {
        return toAjax(proprietorBillService.deleteProprietorBillByProprietorBillIds(proprietorBillIds));
    }


    /**
     * 线下支付
     *
     * @param proprietorBill
     * @return
     */
    @PreAuthorize("@ss.hasPermi('bill:proprietor:offlinePayment')")
    @PostMapping("/offlinePayment")
    public AjaxResult offlinePayment(@RequestBody ProprietorBill proprietorBill) {
        return toAjax(proprietorBillService.offlinePayment(proprietorBill));
    }


    // /**
    //  *
    //  */
    // @GetMapping("/test")
    // public void test() {
    //     proprietorBillService.proprietorBillOvertimeTask();
    // }
}
